<?php
/**
 * 插件管理Control类
 * @file			PluginsControl.class.php
 * @author     	kelecode@gmail.com
 * @date       	2014-03-09
 * modify
 */
class PluginsControl extends Control{

	public function __construct(){
		parent::__construct();
		
		$css = APP_ROOT . '/template/' . C('theme') . '/common/css.php';
		$script =  APP_ROOT . '/template/' . C('theme') . '/common/js.php';
		$mainSubMenu = APP_ROOT . '/template/' . C('theme') . '/plugins/main_sub_menu.php';
		$this->assign('css',$css);
		$this->assign('script',$script);
		$this->assign('mainSubMenu',$mainSubMenu);
	}

	public function index(){
		$this->lists();
	}

	/**
	 * 插件列表
	 */
	public function lists(){
		$type = trim(getgpc('type'));
		$items = M('Plugins')->pluginList($type);
		$tinyPage = new TinyPage( $items['count'],C('page.page_size') );
        $page = $tinyPage->show();

		$main = APP_ROOT . '/template/' . C('theme') . '/plugins/lists.php';
		$this->assign('main', $main);
		$this->assign('title', '插件列表');
		$this->assign('lists', $items['lists']);
		$this->assign('page', $page);
		$this->display('layout', 'common');
	}

	/**
	 * 更新插件状态
	 */
	public function updateStatus(){
		$names = trim( getgpc('names') );
		$names = explode(',',$names);
		$status = (int)getgpc('status');
		is_null($names) && ajaxReturn('','请选择要操作的插件', 0);
		$result = M('Plugins')->updateStatus($names, $status);
		$info = '操作'.($result ?  '成功' : '失败');
		$status = (int)$result;
		ajaxReturn('',$info,$status);
	}

	public function set(){
		echo 'set';
	}

	public function uninstall(){
		echo 'uninstall';
	}

}